package com.zyasdk.util;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.text.TextUtils;

public class LanguageUtil {

	
	public static String getDefaultLanguage(Context context){
		Locale locale = context.getResources().getConfiguration().locale;
		String language = locale.getLanguage();
		if (!TextUtils.isEmpty(language) && ("cn".equalsIgnoreCase(language)||"zh".equalsIgnoreCase(language)||"zh_CN".equalsIgnoreCase(language)
				||"zh_TW".equalsIgnoreCase(language))) {
			return "cn";
		} else {
			return "en";
		}
	}
	
	
	
	public static String getCountry(Context context){
		return context.getResources().getConfiguration().locale.getCountry();
	}
	
	public static String getLanguage(Context context){
		return context.getResources().getConfiguration().locale.getLanguage();
	}
	
	
	public static boolean isChineseChar(String str){
	       boolean temp = false;
	       Pattern p=Pattern.compile("[\u4e00-\u9fa5]");
	       Matcher m=p.matcher(str);
	       if(m.find()){
	           temp =  true;
	       }
	       return temp;
	   }
	public static boolean isChinese(String str){

		char[] c=str.toCharArray();
		int size=c.length;
		for(int i=0;i<size;i++){
			if(isChinese(c[i])){
				return true;
			}
		}
		return false;
	}
	
	 public static boolean isChinese(char c) {
	        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
	        if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
	                || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
	                || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
	                || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
	                || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
	                || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
	            return true;
	        }
	        return false;
	    } 
}
